package com.aurora.color;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.Window;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/**
 * 设置状态栏
 */
public class Utils {

    /**
     * 短提示
     */
    public static void sToast(Activity act, String msg) {
        Toast.makeText(act, msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * 长提示
     */
    public static void lToast(Activity act, String msg) {
        Toast.makeText(act, msg, Toast.LENGTH_LONG).show();
    }


    /**
     * @param color 颜色
     */
    public static void setBarColor(Activity act, int color) {
        try {
            Window window = act.getWindow();
            window.setStatusBarColor(color);
        } catch (Exception e) {
            //抛出异常
            e.printStackTrace();
        }
    }

    /**
     * 复制内容到剪切板
     *
     * @param content 要复制的内容
     */
    public static void clipContent(Activity act, String content) {
        //获取剪切板管理器
        ClipboardManager cm = (ClipboardManager) act.getSystemService(Context.CLIPBOARD_SERVICE);
        //创建普通字符
        ClipData cd = ClipData.newPlainText("Label", content);
        //将内容写入剪切板
        cm.setPrimaryClip(cd);
    }

    /**
     * 读取包内txt文件
     *
     * @param act 当前activity
     * @param dir 文件目录
     */
    public static String getTxtContent(Activity act, int dir) {
        InputStream inputStream = act.getResources().openRawResource(dir);
        InputStreamReader inputStreamReader = null;
        try {
            inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        BufferedReader br = new BufferedReader(inputStreamReader);
        StringBuilder data = new StringBuilder();

        String line;
        try {
            while ((line = br.readLine()) != null) {
                data.append(line).append("\n");
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        return data.toString();
    }

}



